package com.baizhi.controller;

import com.baizhi.entity.Student;
import com.baizhi.service.StudentService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("student")
public class StudentController {
    private StudentService ss;
    @ResponseBody
    @RequestMapping("selectByPage")
    public PageInfo<Student> selectByPage(@RequestParam(defaultValue = "1") int pageNo){
        return ss.selectByPage(pageNo,3);
    }
    @ResponseBody
    @RequestMapping("selectOne")
    public Student selectOne(int id){
        return ss.selectOne(id);
    }
    @ResponseBody
    @RequestMapping("insert")
    public void insert(Student stu){
        ss.insert(stu);
    }
    @ResponseBody
    @RequestMapping("delete")
    public void delete(int id){
        ss.delete(id);
    }
    @ResponseBody
    @RequestMapping("update")
    public void update(@RequestBody Student stu){
        System.out.println(stu);
        ss.update(stu);
    }
    @ResponseBody
    @RequestMapping("delMany")
    public void delMany(int[] ids){
        if(ids!=null){
            for(int id:ids){
                ss.delete(id);
            }
        }
    }

    public StudentService getSs() {
        return ss;
    }

    public void setSs(StudentService ss) {
        this.ss = ss;
    }
}
